require 'erb'

before "deploy:setup", :webapp_config
after "deploy:update_code", "webapp_config:symlink" 

namespace :webapp_config do
  desc "Create webapp config yaml in shared path" 
  task :default do
    webapp_config = ERB.new <<-EOF
    defaults: &defaults
      template: default
      template_css: /templates/default/default.css
      images_dir: /templates/default/images/
      #Uncomment the following line if you have a URL serving static files (images, CSS)
      #statics_url: http://someurl.com
      #Comment this param if the FB users using the FB App dont need to provide their email to register
      require_fb_app_user_email: false
      webapp_name: #{application}
      webapp_site: #{webapp_site}
      webapp_domain: #{webapp_domain}
      facebook_app_id: #{facebook_app_id}
      emails:
       info_from: info@thewebdawn.net
      smtp_settings:
        address: smtp1.servage.net
        port: 25
        domain: thewebdawn.net
        user_name: info@thewebdawn.net
        password: Planta098=)(

    development:
      <<: *defaults
    test:
      <<: *defaults
    production:
      <<: *defaults
    EOF

    run "mkdir -p #{shared_path}/config" 
    put webapp_config.result, "#{shared_path}/config/webapp_config.yml" 
  end

  desc "Make symlink for webapp config yaml" 
  task :symlink do
    run "ln -nfs #{shared_path}/config/webapp_config.yml #{release_path}/config/webapp_config.yml" 
  end
end
